package util

import (
	"github.com/gin-gonic/gin"
	"strconv"
)

type PageInfo struct {
	Size   int
	Offset int
}

func GetPageInfo(c *gin.Context) PageInfo {
	page := c.Query("page")
	size := c.Query("size")

	var p int
	var s int
	if page != "" {
		p, _ = strconv.Atoi(page)
	} else {
		p = 1
	}
	if size != "" {
		s, _ = strconv.Atoi(size)
	} else {
		s = 15
	}

	return PageInfo{
		Size:   s,
		Offset: (p - 1) * s,
	}
}
func GetPageSize(c *gin.Context) (int, int) {
	page := c.DefaultQuery("page", "1")
	size := c.DefaultQuery("size", "15")
	var p int
	var s int
	if page != "" {
		p, _ = strconv.Atoi(page)
	} else {
		p = 1
	}
	if size != "" {
		s, _ = strconv.Atoi(size)
	} else {
		s = 15
	}
	return p, s
}
